/*! \file HXEvents.h
    \brief Thinking Head event client for Head X.

	Head X | Flinders University | Martin Luerssen & Trent Lewis | 2009+
*/

#pragma once

#define MAX_SPEECH_QUEUE 5
#define EVENT_POLL_SLEEP 50

#include <list>

using namespace std;

class HXEventClient
{
public:
	HXEventClient();
	~HXEventClient();

	void SetMenu(HMENU hMenu, int itemId, int sendId, int recvId);
	void SetParentWindow(HWND hwnd) { m_hWnd = hwnd; }
	void SetSend(bool on) { m_bSend = on; }
	bool GetSend() { return m_bSend; }
	void SetReceive(bool on) { m_bReceive = on; }
	bool GetReceive() { return m_bReceive; }

	void Connect();
	bool IsConnected() { return m_bConnected; }
	void Disconnect();

	void SendPersonSpoke(const string& sps);


	void SendRenderComplete();

protected:
	static DWORD WINAPI RunClientThread(LPVOID lpParam);
	DWORD WINAPI ClientThread();
	
	HANDLE m_hThread;
	string m_personSpokeBuffer;
	int m_renderComplete;
	bool m_bThreadExit, m_bConnected, m_bSend, m_bReceive;
	list<void*> m_waitlist;
	HMENU m_hMenu;
	int m_itemId, m_sendId, m_recvId;
	HWND m_hWnd;

	string m_eventCfgFname;

	CRITICAL_SECTION	m_criticalSection_Event;
};

extern HXEventClient g_THEvents;